#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
char s[110][1110];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m,x,y;
		int num = 0;
		scanf("%d %d %d %d",&n,&m,&x,&y);
		for(int i = 0;i<n;i++)
		{
			for(int j = 0;j<m;j++)
			{
				scanf(" %c",&s[i][j]);
				if(s[i][j]=='.') num++;
			}
		}
		int ans = 0;
		if(2*x<=y) printf("%d\n",num*x);
		
		else 
		{
			for(int i = 0;i<n;i++)
			{
				for(int j = 0;j<m;)
				{
					if(s[i][j]=='.'&&s[i][j+1]=='.'&&j+1<m)
					{
						ans += y;
						j += 2;
					}
					else if(s[i][j]!='*') 
					{
						ans += x;
						j++;
					}
					else j++;
				}
			}
			printf("%d\n",ans);
		}
	}
} 
